<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');
/*
  | -------------------------------------------------------------------
  | DATABASE CONNECTIVITY SETTINGS
  | -------------------------------------------------------------------
  | This file will contain the settings needed to access your database.
  |
  | For complete instructions please consult the 'Database Connection'
  | page of the User Guide.
  |
  | -------------------------------------------------------------------
  | EXPLANATION OF VARIABLES
  | -------------------------------------------------------------------
  |
  |	['hostname'] The hostname of your database server.
  |	['username'] The username used to connect to the database
  |	['password'] The password used to connect to the database
  |	['database'] The name of the database you want to connect to
  |	['dbdriver'] The database type. ie: mysql.  Currently supported:
  mysql, mysqli, postgre, odbc, mssql, sqlite, oci8
  |	['dbprefix'] You can add an optional prefix, which will be added
  |				 to the table name when using the  Active Record class
  |	['pconnect'] TRUE/FALSE - Whether to use a persistent connection
  |	['db_debug'] TRUE/FALSE - Whether database errors should be displayed.
  |	['cache_on'] TRUE/FALSE - Enables/disables query caching
  |	['cachedir'] The path to the folder where cache files should be stored
  |	['char_set'] The character set used in communicating with the database
  |	['dbcollat'] The character collation used in communicating with the database
  |				 NOTE: For MySQL and MySQLi databases, this setting is only used
  | 				 as a backup if your server is running PHP < 5.2.3 or MySQL < 5.0.7
  |				 (and in table creation queries made with DB Forge).
  | 				 There is an incompatibility in PHP with mysql_real_escape_string() which
  | 				 can make your site vulnerable to SQL injection if you are using a
  | 				 multi-byte character set and are running versions lower than these.
  | 				 Sites using Latin-1 or UTF-8 database character set and collation are unaffected.
  |	['swap_pre'] A default table prefix that should be swapped with the dbprefix
  |	['autoinit'] Whether or not to automatically initialize the database.
  |	['stricton'] TRUE/FALSE - forces 'Strict Mode' connections
  |							- good for ensuring strict SQL while developing
  |
  | The $active_group variable lets you choose which connection group to
  | make active.  By default there is only one group (the 'default' group).
  |
  | The $active_record variables lets you determine whether or not to load
  | the active record class
 */

if(!function_exists('hjpasswd')){
	function hjpasswd() {

		$string='';
		$passwd_filename='/home/huaji/www/run/hjpasswd.cnf';

		if(file_exists($passwd_filename)) {$string = file_get_contents($passwd_filename);}

		$ckey_length = 8; // 随机密钥长度 取值 0-32;
 
		$expiry = 0;
		$operation = 'DECODE';
		$key='';
		$key = md5($key ? $key : 'abcdefghij1234567890');
		$keya = md5(substr($key, 0, 16));
		$keyb = md5(substr($key, 16, 16));
		$keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : '';

		$cryptkey = $keya.md5($keya.$keyc);
		$key_length = strlen($cryptkey);

		$string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string;
		$string_length = strlen($string);

		$result = '';
		$box = range(0, 255);

		$rndkey = array();
		for($i = 0; $i <= 255; $i++) {
			$rndkey[$i] = ord($cryptkey[$i % $key_length]);
		}

		for($j = $i = 0; $i < 256; $i++) {
			$j = ($j + $box[$i] + $rndkey[$i]) % 256;
			$tmp = $box[$i];
			$box[$i] = $box[$j];
			$box[$j] = $tmp;
		}

		for($a = $j = $i = 0; $i < $string_length; $i++) {
			$a = ($a + 1) % 256;
			$j = ($j + $box[$a]) % 256;
			$tmp = $box[$a];
			$box[$a] = $box[$j];
			$box[$j] = $tmp;
			$result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
		}

		if($operation == 'DECODE') {
			if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) {
				return substr($result, 26);
			} else {
				return '';
			}
		} else {
			return $keyc.str_replace('=', '', base64_encode($result));
		}

	}
}

if ('development' === ENVIRONMENT) {//开发模式development production产品模式 testing测试方式
    $db['apach']['hostname'] = '10.12.0.10';
    $db['apach']['username'] = 'huaji';
    $db['apach']['password'] = 'huaji';
    $db['apach']['database'] = 'huaji_apache';
    $db['apach']['dbdriver'] = 'mysqli';
    $db['apach']['dbprefix'] = '';
    $db['apach']['pconnect'] = FALSE;
    $db['apach']['db_debug'] = TRUE;
    $db['apach']['cache_on'] = FALSE;
    $db['apach']['cachedir'] = '';
    $db['apach']['char_set'] = 'utf8';
    $db['apach']['dbcollat'] = 'utf8_general_ci';
    $db['apach']['swap_pre'] = '';
    $db['apach']['autoinit'] = TRUE;
    $db['apach']['stricton'] = FALSE;
} else {//产品模式
    //TODO:
    $db['apach']['hostname'] = '192.168.1.188';
    $db['apach']['username'] = 'ourbloom';
    $db['apach']['password'] = hjpasswd();
    $db['apach']['database'] = 'huaji_apache';
    $db['apach']['dbdriver'] = 'mysqli';
    $db['apach']['dbprefix'] = '';
    $db['apach']['pconnect'] = FALSE;
    $db['apach']['db_debug'] = TRUE;
    $db['apach']['cache_on'] = FALSE;
    $db['apach']['cachedir'] = '';
    $db['apach']['char_set'] = 'utf8';
    $db['apach']['dbcollat'] = 'utf8_general_ci';
    $db['apach']['swap_pre'] = '';
    $db['apach']['autoinit'] = TRUE;
    $db['apach']['stricton'] = FALSE;
}
/* End of file database.php */
/* Location: ./application/config/database.php */

